﻿using DevExpress.ExpressApp.DC;
using DevExpress.Persistent.Base;
using System.Xml.Linq;

namespace EasyXaf.LowCode.WorkflowEditors.Models.Activities;

[DomainComponent]
[ImageName("WF_Exception")]
[XafDisplayName("异常(Exception)")]
[ActivityGroup(ActivityGroupConsts.ExceptionGroupName)]
public class ExceptionActivity : Activity, IEndActivity
{
    [XafDisplayName("代码")]
    public int Code
    {
        get => GetPropertyValue<int>();
        set => SetPropertyValue(value);
    }

    [XafDisplayName("消息")]
    public string Message
    {
        get => GetPropertyValue<string>();
        set => SetPropertyValue(value);
    }

    public override string ImageName => "WF_Exception";

    public override string Color => "#C0392B";

    public override bool AllowMove => false;

    public override bool AllowCopy => false;

    public override bool HasDetailView => true;

    public ExceptionActivity(IWorkflow workflow, ISequence sequence)
        : base(workflow, sequence)
    {
        Caption = "异常";
    }

    public override void WriteStateToXml(XElement element)
    {
        base.WriteStateToXml(element);

        SetXmlValue(element, nameof(Code), Code);
        SetXmlValue(element, nameof(Message), Message);
    }

    public override void ReadStateFromXml(XElement element)
    {
        base.ReadStateFromXml(element);

        Code = GetXmlValue<int>(element, nameof(Code));
        Message = GetXmlValue<string>(element, nameof(Message));
    }
}
